﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Web.UI;

namespace Royaumes_Libres.Database
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks>Patrick Chabot</remarks>
    public class cOwnerBuildings
    {
        protected string pName;
        protected int pQuantity;
        protected bool pUniqueBuild;
        protected string pImgUrl;

        public string Name { get { return this.pName; } }
        public int Quantity { get { return this.pQuantity; } }
        public bool UniqueBuild { get { return this.pUniqueBuild; } }
        public string ImgUrl { get { return this.pImgUrl; } }

        protected cOwnerBuildings() { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="PkKingdom"></param>
        /// <returns></returns>
        /// <remarks>Patrick Chabot</remarks>
        public static cOwnerBuildings[] GetOwnerBuildings(int PkKingdom)
        {
            SqlCommand cmd = cSQL.GetDbJeuCommand();
            List<cOwnerBuildings> lst = new List<cOwnerBuildings>();
            cOwnerBuildings ob;

            cmd.Connection.Open();
            cmd.CommandText = "spGetOwnerBuildings";
            cmd.Parameters.Add(cSQL.Param("@PkKingdom", PkKingdom, SqlDbType.Int));
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                ob = new cOwnerBuildings();

                ob.pName = dr.GetString(0);
                ob.pQuantity = dr.GetInt32(1);
                ob.pUniqueBuild = dr.GetBoolean(2);
                ob.pImgUrl = dr.GetString(3);

                lst.Add(ob);
            }

            cmd.Connection.Close();
            return lst.ToArray();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        /// <remarks>Patrick Chabot</remarks>
        public ucOwnerBuilding GetControl(Page p)
        {
            if (this.pQuantity == 0) { return null; }

            ucOwnerBuilding uc = (ucOwnerBuilding)p.LoadControl("ucOwnerBuilding.ascx");
            uc.Building = this;
            return uc;
        }
    }
}